﻿// 项目：	Guan.CMS.Data - Guan.CMS
// 文件名：	PublishedRepository.cs
// 
// 修改时间：2013-03-09 1:18
// 修改人：	Cooclsee

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Guan.CMS.Model.Entities;

namespace Guan.CMS.Data.Infrastructure
{
    public class PublishedRepositoryBase<T> : RepositoryBase<T>, IPublishedRepository<T>
        where T : CommonPublishedModel, new()
    {
        public PublishedRepositoryBase(IDatabaseFactory databaseFactory) : base(databaseFactory)
        {
        }

        public IQueryable<T> GetList(bool showHidden = false)
        {
            return base.GetList(c => (showHidden || c.IsPublished) && !c.IsDeleted);
        }

        public IQueryable<T> GetList(Expression<Func<T, bool>> where, bool showHidden = false)
        {
            return base.GetList(where).Where(c => (showHidden || c.IsPublished) && !c.IsDeleted);
        }

        public IEnumerable<T> GetAll(bool showHidden = false)
        {
            return this.GetList(showHidden).AsEnumerable();
        }

        public IEnumerable<T> GetMany(Expression<Func<T, bool>> where, bool showHidden = false)
        {
            return this.GetList(where, showHidden).AsEnumerable();
        }
    }
}